package planclient;

import java.awt.Image;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import modele.Employe;
import modele.Employes;

import org.eclipse.core.internal.runtime.InternalPlatform;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.di.Persist;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.widgets.*;
import org.osgi.framework.BundleContext;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;


public class AffEmployeDetail   {

	private Text txtInput;
	private TableViewer viewer;
	Employes listeEmployes;

	@Inject
	private MDirtyable dirty;
	private FormToolkit toolkit;
 	private Form form;

	@PostConstruct
	public void createComposite(Composite parent) {
		  FormToolkit toolkit = new FormToolkit(parent.getDisplay());
		    final ScrolledForm form = toolkit.createScrolledForm(parent);
		    form.setText("Détails");
		    form.getBody().setLayout(new GridLayout());
		    //toolkit.createButton(form.getBody(), "Checkbox", SWT.CHECK);
		    
		    final Label dateNaissance = toolkit.createLabel(form.getBody(), "00/00/00 " );
		    // Lets make a layout for the first section of the screen
		    GridLayout  layout = new GridLayout();
		    layout.numColumns = 1;
		    layout.marginWidth = 0;
		    layout.marginHeight = 0;
		    
		    
		    // Creating the Screen
		    Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION
		        | Section.TITLE_BAR);
		    section.setText("Contrat"); //$NON-NLS-1$
		    section.setDescription("This demonstrates the usage of section");
		    toolkit.createLabel(form.getBody(), "To define");
		    // Composite for storing the data
		   
		    
			//gestion evt
			BundleContext ctx = InternalPlatform.getDefault().getBundleContext();
			 EventHandler handler = new EventHandler() {
				 @Override 
				 public void handleEvent(final Event event) {
					 Employe e = (Employe) event.getProperty("Employe");
					 if (e!= null) {
						 log.logger.Infologg("[TEST OK message Recu]" + event.getProperty("Employe"));
						 form.setText(e.getNom() + " " + e.getPrenom());
						 dateNaissance.setText(e.getDateNaissance());
					 }
			        }
			 };
		     Dictionary<String, String> properties = new Hashtable<String, String>();
		     properties.put(EventConstants.EVENT_TOPIC, "Employes/*");
		     ctx.registerService(EventHandler.class, handler, properties);
		    
		    
		  }



	@Focus
	public void setFocus() {
		
		//viewer.getTable().setFocus();
	}

	@Persist
	public void save() {
		dirty.setDirty(false);
	}
	
}
